﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing;
using System.Drawing.Imaging;

namespace XianboSite.Utility
{
    public class ImageResult : ActionResult
    {
        // 图片
        public Image imageData;

        // 构造器
        public ImageResult(Image image)
        {
            imageData = image;
        }

        // 主要需要重写的方法
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpResponseBase response = context.HttpContext.Response;

            // 设置 HTTP Header
            response.ContentType = "image/jpeg";

            // 将图片数据写入Response
            imageData.Save(context.HttpContext.Response.OutputStream, ImageFormat.Jpeg);
        }

        //Response.AddHeader("ContentType", "image/jpeg;");
        //".asf" ContentType ="video/x-ms-asf"
        //".avi" ContentType ="video/avi"
        //".doc" ContentType ="application/msword"
        //".xls" ContentType ="application/vnd.ms-excel"
        //".pdf" ContentType ="application/pdf"
        //".ppt" ContentType ="application/vnd.ms-powerpoint"
        //".gif" ContentType ="image/gif"
        //".jpg" ContentType ="image/jpeg"
        //".jpe" ContentType ="image/jpeg"
        //"jpeg" ContentType ="image/jpeg"
        //".bmp" ContentType ="image/bmp"
        //".txt" ContentType ="application/text"
        //".txt" ContentType ="application/zip"
        //".zip" ContentType ="application/zip"
        //".wav" ContentType ="audio/wav"
        //".mp3" ContentType ="audio/mpeg3"
        //".mpg","mpeg" ContentType ="video/mpeg"
        //".rtf" ContentType ="application/rtf"
        //".htm","html" ContentType ="text/html"
        //".asp" ContentType ="text/asp"
        //other:  ContentType ="application/octet-stream"
    }
}